unit uCalcVolum;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, cxGroupBox, cxTextEdit, Vcl.StdCtrls, Vcl.Menus, cxButtons,System.Math;

type
  TFrmCalcVolum = class(TForm)
    cxGroupBox1: TcxGroupBox;
    edtLong: TcxTextEdit;
    edtWidth: TcxTextEdit;
    edtHeight: TcxTextEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    edtCnt: TcxTextEdit;
    procedure cxButton1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure edtLongKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
  private
    rVolum:Real;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmCalcVolum: TFrmCalcVolum;
  function FrmCalcVolumForm(var icnt:Integer):Real;

implementation

{$R *.dfm}

uses ucommFunction, uDm;

function FrmCalcVolumForm(var icnt:Integer):Real;
begin
  Application.CreateForm(TFrmCalcVolum,FrmCalcVolum);
  with FrmCalcVolum do
  begin
    edtCnt.Text:=IntToStr(icnt);
    if ShowModal=mrOk then
    begin
      Result:=rVolum;
      if not TryStrToInt(edtCnt.Text,icnt) then
        icnt:=1;
    end else
      Result:=0;
    FreeAndNil(FrmCalcVolum);
  end;
end;

procedure TFrmCalcVolum.cxButton1Click(Sender: TObject);
var
  Long,width,height:Extended;
  cnt:integer;
begin
  try
    rVolum:=0;
    if not TryStrToFloat(edtLong.Text,Long) then
      Long:=0;
    if not TryStrToFloat(edtWidth.Text,width) then
      width:=0;
    if not TryStrToFloat(edtHeight.Text,height) then
      height:=0;
    if not TryStrToInt(edtCnt.Text,cnt) then
      cnt:=1;
    rVolum:=RoundTo(long/100*width/100*height/100*cnt,-2);
  except

  end;
end;

procedure TFrmCalcVolum.edtLongKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    SelectNext(ActiveControl, True, True);
end;

procedure TFrmCalcVolum.FormCreate(Sender: TObject);
begin
  pSetCaption(Self);
end;

procedure TFrmCalcVolum.FormShow(Sender: TObject);
begin
  edtLong.SetFocus;
end;

end.
